package servlets;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import dao.Fundraising_projectDao;

public class FindOrInsertServlet extends HttpServlet{
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doPost(req, resp);
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		String sid = req.getParameter("sid");
		HttpSession session = req.getSession();
		String choice_id = (String) session.getAttribute("choice_id");
		
		int find_insert_id = Integer.parseInt(sid);
		
		if(!"1".equals(sid) && "4".equals(choice_id)){
			session.setAttribute("find_insert_id", 9);
			ArrayList<String> project_title_list = new Fundraising_projectDao().getAllTitles();
			session.setAttribute("project_title_list", project_title_list);
		} else {
			session.setAttribute("find_insert_id", find_insert_id);
		}
		
		String id = (String)session.getAttribute("choice_id");
		resp.sendRedirect("houtai/guanli_1.jsp?id="+id);
	}
}
